#include "losu.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* need  config */
#include "pkgs.inc"

static const char __main__[] =
#include "main.els.inc"
    ;

/* main */
int32_t
main (int32_t argc, const char **argv)
{
  int32_t i = 0;
  LosuVm *vm = vm_create (1024);
  if (vm == NULL)
    return -1;
  LosuPackages = &_inlinePkgs[0];
  vm_init (vm, argc - 1, argv + 1);
  if (argc == 1)
    {
      printf ("Losu %s [%s] for %s\nCopyright (c) %s\nHome: "
              "https://losu.tech\n--------------------------------\n",
              LosuVersion, LosuBuild, LosuArch, LosuCopyright);
      while (1)
        {
          vm_dobyte (vm, __main__, sizeof (__main__), "main.els");
        }
    }
  else
    {
      if (strcmp (argv[1], "-v") == 0)
        printf ("%s\n", LosuVersion);
      else if (strcmp (argv[1], "-h") == 0)
        printf (
            "Usage:\n\tlosu -v     |show version \n\tlosu -h     |show help "
            "\n\tlosu        |play with REPL  \n\tlosu [file] |exec file\n");
      else
        i = vm_dofile (vm, argv[1]);
    }

  vm_close (vm);
  return i;
}